package gupao.concurrency.api.sample;

import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
 * An API Future represents the result of an asynchronous computation.
 * 
 * @see Future
 * @author wilson
 * @param <V>
 */
public interface ApiFuture<V> extends Future<V>
{

	/**
	 * Waits if necessary for the computation to complete, and then retrieves its result.
	 * 
	 * @see Future#get()
	 */
	public V getResult() throws InterruptedException, ExecutionException;

	/**
	 * Waits if necessary for the computation to complete, and then retrieves API call info.
	 * 
	 * @see Future#get()
	 */
	public List<ApiInvokeInfo> getInvokeInfo();

	/**
	 * Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.
	 * 
	 * @see Future#get(long, TimeUnit)
	 */
	public V getResult(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException;

	/**
	 * Waits if necessary for at most the given time for the computation to complete, and then retrieves API call info, if
	 * available.
	 * 
	 * @see Future#get(long, TimeUnit)
	 */
	public List<ApiInvokeInfo> getInvokeInfo(long timeout, TimeUnit unit);

}
